package com.mingzhi.rabbitextensiondemo.config;

import com.mingzhi.rabbitextensiondemo.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitMQConfig {
    /**
     * 创建队列
     * @return
     */
    @Bean("ackQueue")
    public Queue ackQueue(){
        return QueueBuilder.durable(Constants.ACK_QUEUE).build();
    }

    /**
     * 创建交换机
     * @return
     */
    @Bean("directExchange")
    public DirectExchange ackExchange(){
        return ExchangeBuilder.directExchange(Constants.ACK_EXCHANGE).durable(true).build();
    }
    /**
     * 绑定队列和交换机
     * @return
     */
    @Bean("ackBinding")
    public Binding ackBinding(@Qualifier("directExchange")DirectExchange directExchange,
                              @Qualifier("ackQueue")Queue queue){
        return BindingBuilder.bind(queue).to(directExchange).with("ack");
    }



}
